/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package functions;

import Interfaces.Loadable;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JArik
 */
public class LogError extends HTTPRequest
{
    private static String logURL = Dogy.WEB_CONTROL_URL+"/addError.php";
    public LogError(Object error)
    {
        HashMap vars = new HashMap();
        vars.put("version", Dogy.VERSION);
        vars.put("prefix", Dogy.V_PREFIX);
        vars.put("error", error+"");
        this.setVars(vars);
        this.url = logURL;
    }
    public static void reportSilentError(Exception e)
    {
        try {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        LogError le = new LogError(sw.toString());        
        le.sendRequest(new Loadable() {

                @Override
                public Object load()
                {
                    return null;
                }

                @Override
                public Object cancel()
                {
                    return null;
                }

                @Override
                public void done(Object done) {
                }

                @Override
                public void progress(int p) {
                }
            });
        } catch (MalformedURLException ex) {
            Logger.getLogger(LogError.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(LogError.class.getName()).log(Level.SEVERE, null, ex);
        } catch(Exception ex)
        {
            Logger.getLogger(LogError.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
